import Vue from 'vue'
import App from './App.vue'
import router from './router'
import './plugins/element.js'
import '../src/assets/global.css'
import { MessageBox } from 'element-ui';

// element组件按需导入
import {
  Form, FormItem, Input, Button, Message,
  Header, Container, Aside,
  Main, Menu, Submenu, MenuItem, Breadcrumb,
  BreadcrumbItem, Card, Row, Col, Table, TableColumn,
  Switch, Tooltip, Pagination, Dialog, Tag, Tree,
  Select, Option, Cascader, Alert, Tabs, TabPane, Steps,
  Step, CheckboxGroup, Checkbox, Upload, Timeline, TimelineItem
} from 'element-ui'

import './assets/fonts/iconfont.css'
import axios from 'axios'
// 配置请求根路径
axios.defaults.baseURL = 'http://127.0.0.1:8888/api/private/v1/'
// 设置拦截器
axios.interceptors.request.use(config => {
  // 最后必须ruturn config
  config.headers.Authorization = window.sessionStorage.getItem('token');
  return config;
})
// 导入富文本编辑器
import VueQuillEditor from 'vue-quill-editor'
//倒入富文本编辑器对应的样式
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
// 全局注册富文本编辑器
Vue.use(VueQuillEditor)

Vue.prototype.$http = axios
Vue.use(Timeline)
Vue.use(TimelineItem)
Vue.use(TabPane)
Vue.use(Form)
Vue.use(FormItem)
Vue.use(Input)
Vue.use(Button)
Vue.use(Header)
Vue.use(Container)
Vue.use(Aside)
Vue.use(Main)
Vue.use(Menu)
Vue.use(Submenu)
Vue.use(MenuItem)
Vue.use(Breadcrumb)
Vue.use(BreadcrumbItem)
Vue.use(Card)
Vue.use(Row)
Vue.use(Col)
Vue.use(Table)
Vue.use(TableColumn)
Vue.use(Switch)
Vue.use(Tooltip)
Vue.use(Pagination)
Vue.use(Dialog)
Vue.use(Tag)
Vue.use(Tree)
Vue.use(Select)
Vue.use(Option)
Vue.use(Cascader)
Vue.use(Tabs)
Vue.use(Alert)
Vue.use(TabPane)
Vue.use(Steps)
Vue.use(Step)
Vue.use(CheckboxGroup)
Vue.use(Checkbox)
Vue.use(Upload)

// Message组件需要挂载在VUE上才能使用，Form,FormItem,Input,Button等不需要挂载在vue上
Vue.prototype.$message = Message;
Vue.prototype.$http = axios;
Vue.prototype.$confirm = MessageBox.confirm;
Vue.config.productionTip = false;

import TreeTable from 'vue-table-with-tree-grid'
Vue.component('tree-table', TreeTable)

// 时间过滤器
Vue.filter('dateFormat', function (originVal) {
  let dt = new Date(originVal)
  let y = dt.getFullYear();
  let m = dt.getMonth() + 1;
  m = m > 9 ? m : '0' + m;
  let d = dt.getDate();
  d = d > 9 ? d : '0' + d;
  let hh = dt.getHours()
  hh = hh > 9 ? d : '0' + d;
  let mm = dt.getMinutes()
  mm = mm > 9 ? d : '0' + d;
  let ss = dt.getSeconds()
  ss = ss < 10 ? '0' + ss : ss
  return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
})

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
